﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Configuration.Install;
using System.Collections;

namespace WindowsService
{
    static class Program
    {
        /// <summary>
        /// Punto di ingresso principale dell'applicazione.
        /// </summary>
        public static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                {
                    ServiceBase[] ServicesToRun;
                    ServicesToRun = new ServiceBase[] 
			                                        { 
				                                        new Service1() 
			                                        };
                    ServiceBase.Run(ServicesToRun);
                }
                else
                {
                    bool install = false, uninstall = false;
                    switch (args[0])
                    {
                        case "-i":
                        case "-install":
                            install = true;
                            break;
                        case "-u":
                        case "-uninstall":
                            uninstall = true;
                            break;
                    }
                    if (install)
                        WMISrvc.Installer.Install(true);
                    if (uninstall)
                        WMISrvc.Installer.Install(false);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}
